<template>
  <div>
    <span style="top:50%">{{msg}}</span>
  </div>
</template>
<script>
import { sign, signStr } from "@/assets/js/sign.js";
import { isWeiXin, urlParse } from "@/assets/js/utils"; //获取url参数
export default {
  data() {
    return {
      msg: "正在加载……"
    };
  },
  methods: {
    getInfo(code){
      let urlparam = sign("/v1/api/FindQrCode");
      urlparam.append("QrCode", code);
      this.$http.post("/FindQrCode", urlparam).then(ret => {
        if (ret.status == 200) {
          var _data = ret.data.resultObject;
          var _code = ret.data.code || ret.data.result.code;
          var _msg = ret.data.msg || ret.data.result.msg;

          if (_code == 1) {
            //存储起来
            //存储商家信息
            this.$store.commit("addSellerInfo", _data.Seller);
            //存储餐桌信息
            this.$store.commit("addCzInfo", _data.BcanzwhVo);

            let url = localStorage.getItem("beforeUrl");
            localStorage.removeItem("beforeUrl");
            if (url == null || url == "" || url == undefined) {
              this.$router.replace("/Seller/" + _data.Seller.id + "/0");
            } else {
              this.$router.replace(url);
            }
          } else {
          }
        } else {
          this.$vux.toast.text(ret.data.msg, "top");
        }
      });
    }
  },
  created() {
    // if(isWeiXin()==false){
    //   this.msg="请使用微信客户端打开页面！";
    //   return;
    // }

    
    let params = urlParse();

    // if (!params.hasOwnProperty("code")) {
    //   params = urlParse(localStorage.getItem("baseurl"));
    // }

    if (params.hasOwnProperty("code")) {
      this.getInfo(params["code"]);
    } else {
      
      this.msg = "无法定位到商家";
    }
  }
};
</script>


